﻿<HTML>
<HEAD><TITLE>后台管理系统</TITLE>

    <META http-equiv=Content-Type content="text/html; charset=utf-8">
    <META content="Microsoft FrontPage 4.0" name=GENERATOR>

    <script src="__FINANCE__/Scripts/jquery.js" charset="utf-8"></script>
    <script src="__FINANCE__/Scripts/watermarker.js" charset="utf-8"></script>
    <link href="__FINANCE__/layui/css/layui.css" rel='stylesheet' type='text/css'/>
    <script src="__FINANCE__/layui/layui.js" charset="utf-8"></script>
    <!--<script src="__FINANCE__/layer/layer.js" charset="utf-8"></script>-->

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /* 偶数行背景色 */
        .layui-table[lay-even] tr:nth-child(even) {
            /* background-color: #aaffaa; */
            background-color: #eeffee;
        }

        /* 鼠标指向表格时,奇数行背景颜色 */
        .layui-table tbody tr:hover,.layui-table-hover {
            background-color: #abd1f9;
        }

        /*!* 表格头部工具栏背景色 *!*/
        /*.layui-table-tool {*/
        /*background-color: #eeffee;*/
        /*}*/

        /* 表格头部背景色 */
        /*th {*/
        /*background-color: #359f6a; !* MediumSeaGreen *!*/
        /*color: #fff;*/
        /*font-weight: bold*/
        /*}*/


    </style>
</HEAD>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>

        <td width="68%" background="__FINANCE__/Images/b2.jpg">
            <table width="124" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="20" align="left"><img src="__FINANCE__/Picture/tz.gif" width="10" height="16"/></td>
                    <td width="104" align="left" class="biao">查询条件</td>
                </tr>
            </table>
        </td>

    </tr>
</table>
<blockquote class="layui-elem-quote layui-quote-nm" style="margin-bottom: 0px;padding:0px;padding-top: 10px">
    <div class="layui-form-item">
        <form class="layui-form" id="form1" name="form1" method="get" action="">
            <table width="100%" border="0" cellspacing="1" cellpadding="3">
                <tr align="center">
                    <td width="5%">工资年份：</td>
                    <td width="5%"><label>
                        <div class="layui-input-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="date_time" id="date_time"  placeholder=""
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </label></td>
                    {if session('user_name') == 'admin' }
                    <td align="center" width="5%">姓名：</td>
                    <td width="5%">
                        <div class="layui-input-inline">
                            <input type="tel" name="name" id="name" autocomplete="off"
                                   class="layui-input">
                        </div>
                    <td align="center" width="5%">身份证号：</td>
                    <td align="center" width="10%">
                        <input type="text" name="card_num" id="card_num"  placeholder="" autocomplete="off"
                               class="layui-input">
                    </td>
                    {/if}
                    <td width="20%">
                        <div class="layui-input-block">
                            <button type="button" id="search-input" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">
                                <i class="layui-icon">&#xe615;</i>查询
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</blockquote>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td width="68%" background="__FINANCE__/Images/b2.jpg">
            <table width="124" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="20" align="left"><img src="__FINANCE__/Picture/tz.gif" width="10" height="16"/></td>
                    <td width="104" align="left" class="biao">数据列表</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<table class="layui-hide" id="salary_list" lay-filter="salary_list"></table>
<script type="text/html" id="salary_list_toolbar">
    <div class="layui-btn-container">
        {if session('user_name') == 'admin' }
        <button type="button"  class="layui-btn" id="uploadExcel"><i class="layui-icon">&#xe67c;</i>导入</button>
        <button type="button" class="layui-btn layui-btn-normal" id="exportExcel" lay-event="exportExcel"><i class="layui-icon">&#xe601;</i>导出</button>
        <button type="button" class="layui-btn layui-btn-danger" id="deletes" lay-event="deletes"><i class="layui-icon">&#xe640;</i>删除</button>
        {/if}
    </div>
</script>
<script>

    watermark({watermark_txt:'新乡市纪委监委财务管理'});

    layui.use(['table', 'upload','laydate'], function () {
        var table = layui.table
            ,$ = layui.jquery
           , layer = layui.layer
            , laydate = layui.laydate
            , upload = layui.upload;
        //日期
        laydate.render({
            elem: '#date_time'
            , type: 'month'
            ,range: true
        });


        var tableIns = table.render({
            elem: '#salary_list'
            , url: '{:url("/finance/Index/GongZhiChaXun")}'
            , toolbar: '#salary_list_toolbar'
            ,defaultToolbar: ['filter']
            , title: '用户数据表'
            , totalRow: true
            ,height:500
            ,limit:15
            ,limits:[15, 30, 45, 60, 80,100]
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
//                , {field: 'id', title: 'id', width: 60, fixed: 'left', sort: true, totalRowText: '合计'}
//                , {field: 'department', title: '部门', width: 80}
                , {field: 'real_name', title: '人员名称', width: 120,fixed: 'left',align: 'center'}
                , {field: 'card_num', title: '身份证号', width: 150,fixed: 'left',align: 'center'}
//                , {field: 'level_of_wages', title: '应发工资', width: 150, totalRow: true}
//                , {field: 'net_payroll', title: '实发工资', width: 150, totalRow: true}
                , {field: 'date_year', title: '业务年度', width: 120,  fixed: 'left',align: 'center'}
                , {field: 'date_month', title: '月份', width: 80,totalRowText: '合计', align: 'center'}
                , {field: 'technical_grade', title: '职务（技术等级）工资', width: 200,totalRow: true,align: 'center'}
                , {field: 'level_of_wages', title: '级别（岗位）工资', width: 160,totalRow: true,align: 'center'}
                , {field: 'probation_pay', title: '见习期工资', width: 120,totalRow: true,align: 'center'}
                , {field: 'allowance', title: '工作性津贴', width: 120,totalRow: true,align: 'center'}
                , {field: 'subsidy', title: '生活性补贴', width: 120,totalRow: true,align: 'center'}
                , {field: 'price_of_commodities', title: '保留物价福利补贴', width: 160,totalRow: true,align: 'center'}
                , {field: 'special_post_allowance', title: '特殊岗位津贴', width: 120,totalRow: true,align: 'center'}
//                , {field: 'other_subsidy', title: '其它津补贴', width: 120}
//                , {field: 'police_subsidy', title: '警衔、审判、检', width: 120}
//                , {field: 'id', title: '转隶人员绝对值', width: 120}
                , {field: 'civilization_award', title: '省级以下文明奖', width: 150,totalRow: true,align: 'center'}
                , {field: 'above_civilization_award', title: '省级及以上文明', width: 150,totalRow: true,align: 'center'}
                , {field: 'housing_add', title: '住房补贴', width: 120,totalRow: true,align: 'center'}
                , {field: 'back_pay', title: '补发工资', width: 120,totalRow: true,align: 'center'}
//                , {field: 'deduction_of_wages', title: '扣减工资项', width: 120}
//                , {field: 'other', title: '其他', width: 120}
                , {field: 'transport_subsidy', title: '公务交通补贴', width: 120,totalRow: true,align: 'center'}
                , {field: 'should_send', title: '应发项', width: 120,totalRow: true,align: 'center'}
//                , {field: 'year_bonus', title: '年终一资性奖金', width: 120}
//                , {field: 'civilized_city_award', title: '全国文明城市奖', width: 120}
//                , {field: 'assessment_award', title: '年度目标考核奖', width: 120}
//                , {field: 'peacetime_award', title: '平时考核奖', width: 120}
//                , {field: 'heating fee', title: '取暖费', width: 120}
                , {field: 'service_subsidy', title: '物业服务补贴', width: 120,align: 'center'}
                , {field: 'official_call_subsidy', title: '公务通讯补贴', width: 120,align: 'center'}
                , {field: 'accumulation_fund', title: '住房公积金', width: 130,totalRow: true,align: 'center'}
                , {field: 'basic_insurance', title: '基本养老保险', width: 120,totalRow: true,align: 'center'}
                , {field: 'medical_premiums', title: '医疗保险费', width: 120,totalRow: true,align: 'center'}
//                , {field: 'unemployment_insurance ', title: '失业保险', width: 120,}
                , {field: 'occupational_annuity', title: '职业年金', width: 120,totalRow: true,align: 'center'}
                , {field: 'income_tax', title: '所得税', width: 120,totalRow: true,sort: true,}
                , {field: 'garnishment', title: '扣发项', width: 120,totalRow: true,fixed: 'right',align: 'center'}
                , {field: 'net_payroll', title: '实发工资', width: 120,totalRow: true,fixed: 'right',align: 'center'}
            ]]
            , page: true
        });
        //工具栏事件
        table.on('toolbar(salary_list)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
//                case 'exportExcel':
//                    var data = checkStatus.data;
//                    layer.alert(JSON.stringify(data));
//                    break;
                case 'exportExcel': //导出文件
                    var data = checkStatus.data;
//                    layer.msg('选中了：' + data.length + ' 个');
                    //获取选中的ID
                    var checkIdS = '';　//创建一个数组
                    $.each(data,function(k,value){
                        checkIdS += value.id + ',';
                    });
                    //导出文件
                function exportExcel(){
                    var date_time = $('#date_time').val();
                    var name = $('#name').val();
                    var card_num = $('#card_num').val();
                    var form = $("<form>");
                    form.attr('style', 'display:none');
                    form.attr('target', '');
                    form.attr('method', 'post');
                    form.attr('action', '{:url("/finance/Index/exportFile")}');

                    var input1 = $('<input>');
                    input1.attr('type', 'hidden');
                    input1.attr('name', 'name');
                    /* JSON.stringify($.serializeObject($('#searchForm'))) */
                    input1.attr('value', name);

                    var input2 = $('<input>');
                    input2.attr('type', 'hidden');
                    input2.attr('name', 'date_time');
                    input2.attr('value', date_time);

                    var input3 = $('<input>');
                    input3.attr('type', 'hidden');
                    input3.attr('name', 'card_num');
                    input3.attr('value', card_num);

                    //选中的ID
                    var input4 = $('<input>');
                    input4.attr('type', 'hidden');
                    input4.attr('name', 'checkIdS');
                    input4.attr('value', checkIdS);


                    $('body').append(form);
                    form.append(input1);
                    form.append(input2);
                    form.append(input3);
                    form.append(input4);

                    form.submit();
                    form.remove();
                }
                exportExcel();
                    break;
                case 'deletes':
                    var data = checkStatus.data;
                    if(data.length == 0){
                        layer.msg('请选择删除的记录', {icon: 5}); return false;
                    }
                    layer.confirm('确定要删除吗?', {
                        btn: ['确定','取消'], //按钮
                        offset: '100px'
                    }, function(){
                        //获取选中的ID
                        var checkIdS = '';　//创建一个数组
                        $.each(data,function(k,value){
                            checkIdS += value.id + ',';
                        });

                        $.ajax({
                            url: '{:url("/finance/Index/deleteSalary")}',
                            type: 'post',
                            dataType: 'json',
                            data: {checkIdS: checkIdS},
                            cache: false,
                            async: true,
                            beforeSend: function () {
                                layer.load(2);
                            },
                            complete: function () {
                                layer.closeAll('loading');
                            },
                            success: function (res) {
                                if(res.code == 1){
                                    layer.msg('删除成功', {icon: 1});
                                    tableIns.reload({
                                        where: {}
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                    return false;
                                }
                                layer.alert('删除失败', {icon: 2}); return false;
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert('网络失败，请联系管理员', {icon: 2});
                            }
                        });


                    }, function(){
//                        layer.msg('', {
//                            time: 20000, //20s后自动关闭
//                            btn: ['明白了', '知道了']
//                        });
                    });
                    break;
            }
        });
        //搜索重载表格
        $('#search-input').click(function () {
            var date_time = $('#date_time').val();
            var name = $('#name').val();
            var card_num = $('#card_num').val();
            tableIns.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    date_time: date_time
                    , name: name
                    , card_num: card_num
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });


        function uploadRender(){
            upload.render({
                elem: '#uploadExcel'
                , url: '{:url("/finance/Index/uploadExcel")}' //改成您自己的上传接口
                , accept: 'file' //普通文件
                , done: function (res) {
                   if(res.code == 2){
                       layer.confirm('该文件已经导入', {
                           btn: ['覆盖导入','不覆盖导入'] //按钮
                           ,offset: '100px'
                       }, function(){
                           // layer.msg('的确很重要', {icon: 1});
                           //覆盖导入
                           $.ajax({
                               url: '{:url("/finance/Index/getUploadFileData")}',
                               type: 'post',
                               dataType: 'json',
                               data: {file_id: res.data.file_id,type:0,old_file_id: res.data.old_file_id},
                               cache: false,
                               async: true,
                               beforeSend: function () {
                                   layer.load(2);
                               },
                               complete: function () {
                                   layer.closeAll('loading');
                               },
                               success: function (res) {
                                   if(res.code == 1){
                                       layer.msg('导入成功');
                                       window.top.frames['main'].location.href = '{:url("/finance/Index/salary")}';
                                       // uploadRender();
                                       tableIns.reload({
                                           where: {}
                                           , page: {
                                               curr: 1 //重新从第 1 页开始
                                           }
                                       });
                                       return false;
                                   }
                                   layer.alert('导入失败', {icon: 2});
                               },
                               error: function (XMLHttpRequest, textStatus, errorThrown) {
                                   layer.alert('网络失败，请联系管理员', {icon: 2});
                               }
                           });
                       }, function(){
                           //不覆盖导入
                           $.ajax({
                               url: '{:url("/finance/Index/getUploadFileData")}',
                               type: 'post',
                               dataType: 'json',
                               data: {file_id: res.data.file_id,type:1},
                               cache: false,
                               async: true,
                               beforeSend: function () {
                                   layer.load(2);
                               },
                               complete: function () {
                                   layer.closeAll('loading');
                               },
                               success: function (res) {
                                   if(res.code == 1){
                                       layer.msg('导入成功');
                                       window.top.frames['main'].location.href = '{:url("/finance/Index/salary")}';
                                       // uploadRender();
                                       tableIns.reload({
                                           where: {}
                                           , page: {
                                               curr: 1 //重新从第 1 页开始
                                           }
                                       });
                                       return false;
                                   }
                                   layer.alert('导入失败', {icon: 2});
                               },
                               error: function (XMLHttpRequest, textStatus, errorThrown) {
                                   layer.alert('网络失败，请联系管理员', {icon: 2});
                               }
                           });
                           // layer.msg('也可以这样', {
                           //     time: 20000, //20s后自动关闭
                           //     btn: ['明白了', '知道了']
                           // });
                       });
                   }
                    if (res.code == 1) {
                        $.ajax({
                            url: '{:url("/finance/Index/getUploadFileData")}',
                            type: 'post',
                            dataType: 'json',
                            data: {file_id: res.data.file_id},
                            cache: false,
                            async: true,
                            beforeSend: function () {
                                layer.load(2);
                            },
                            complete: function () {
                                layer.closeAll('loading');
                            },
                            success: function (res) {
                                if(res.code == 1){
                                    layer.msg('导入成功');
                                    window.top.frames['main'].location.href = '{:url("/finance/Index/salary")}';
                                    // uploadRender();
                                    tableIns.reload({
                                        where: {}
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                    return false;
                                }
                                layer.alert('导入失败', {icon: 2});
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert('网络失败，请联系管理员', {icon: 2});
                            }
                        });
                    }
                    if (res.code == 0) {
                        layer.msg(res.msg,{icon: 5});
                    }

                }
            });
        }
        uploadRender();
        // //上传excel文件
        // upload.render({
        //     elem: '#uploadExcel'
        //     , url: '{:url("/finance/Index/uploadExcel")}' //改成您自己的上传接口
        //     , accept: 'file' //普通文件
        //     , done: function (res) {
        //         if (res.code == 1) {
        //             $.ajax({
        //                 url: '{:url("/finance/Index/getUploadFileData")}',
        //                 type: 'post',
        //                 dataType: 'json',
        //                 data: {file_id: res.data.file_id},
        //                 cache: false,
        //                 async: true,
        //                 beforeSend: function () {
        //                     layer.load(2);
        //                 },
        //                 complete: function () {
        //                     layer.closeAll('loading');
        //                 },
        //                 success: function (res) {
        //                   if(res.code == 1){
        //                       layer.msg('导入成功');
        //                       // window.top.frames['main'].location.href = '{:url("/finance/Index/salary")}';
        //                           tableIns.reload({
        //                               where: {}
        //                               , page: {
        //                                   curr: 1 //重新从第 1 页开始
        //                               }
        //                           });
        //                       return false;
        //                   }
        //                     layer.alert('导入失败', {icon: 2});
        //                 },
        //                 error: function (XMLHttpRequest, textStatus, errorThrown) {
        //                     layer.alert('网络失败，请联系管理员', {icon: 2});
        //                 }
        //             });
        //         }
        //         if (res.code == 0) {
        //             layer.msg(res.msg,{icon: 5});
        //         }
        //
        //     }
        // });

    });
</script>
</body>
</HTML>